<?php
namespace app\html\controller;
// use app\index\
use think\captcha\Captcha;
class Message extends Base
{
    public function index()
    {      
        $id=request()->param('id'); 
        $viewPage=$this->getIndexPage($id);       
        $systemt=db("systemt");
        $channel=db("channel");
        $fname=$channel->where("id",$id)->value("name");        
        $pid=$channel->where("id=".$id)->value("pid");
        if($pid > 0){
            $gcid=$pid;
            $pcid=$id;
            $lchannel=$this->get_left_channel($gcid);
            $gnavName=$channel->where("id=".$gcid)->value("name");
            $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$id;
            $gnavName=$channel->where("id=".$gcid)->value("name");
            // $where['is_home']=1;
        }
        // SEO META关键字配置
        $meta=$this->getSeoMeta($gnavName,$pnavName);
        $this->assign("meta",$meta);

        $modelx=$channel->where("id",$id)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("cid",$cid);
        $this->assign("gcid",$gcid);
        $this->assign("pcid",$pcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
        return view($viewPage);
    }
    public function domessage()
    {
        $code=$_POST['vercode'];
        
        $checkCerify=$this->checkCerify($code);
        if(!$checkCerify){
            $mess['code']=100;
            $mess['msg']='验证码不正确';
            return json_encode($mess);
        }
        $data['title']=$_POST['title'];
        $data['content']=$_POST['content'];
        $data['username']=$_POST['username'];
        $data['telphone']=$_POST['telphone'];
        $data['uemail']=$_POST['uemail'];
        $data['createtime']=time();
        $res=db("message")->insert($data);
        if($res){
            $mess['code']=200;
            $mess['msg']='留言已收到，我们将会尽快安排时间联系你，请你注意接听电话！';
        }else{
            $mess['code']=100;
            $mess['msg']='提交失败，请重试！';
        }
        return json_encode($mess);
    }
    public function checkCerify($value)
    {
        $captcha = new Captcha();
        return $captcha->check($value);
        // return $captcha->entry();    
    }
}
